package base;

import java.util.ArrayList;
import java.util.List;

public class Reader {
	private String readerId;
    private String name;
    private List<Book> borrowedBooks = new ArrayList<>();
    private static final int MAX_BORROW = 3;

    public Reader(String readerId, String name, String contact) {
        this.readerId = readerId;
        this.name = name;
    }

    public String getReaderId() { return readerId; }
    public String getName() { return name; }

    public void borrowBook(Book book) throws BorrowLimitExceededException, BookAlreadyBorrowedException {
        if (borrowedBooks.size() >= MAX_BORROW) {
            throw new BorrowLimitExceededException(name + " 已达到最大借书数量：" + MAX_BORROW);
        }
        book.borrow(); // 可能抛出 BookAlreadyBorrowedException
        borrowedBooks.add(book);
    }

    public void returnBook(Book book) {
        book.returnBook();
        borrowedBooks.remove(book);
    }

    @Override
    public String toString() {
        return String.format("读者[%s] %s 已借书数量：%d", readerId, name, borrowedBooks.size());
    }
}
